<?php
/**
 * Created by PhpStorm.
 * User: dev
 * Date: 12/11/14
 * Time: 5:16 PM
 */
class Member_Profile_Controller extends Base_Controller
{

	public $restful = true;

	public function __construct()
	{
		parent::__construct();
		//--Your Code --//
		$this->theme->set_theme("default");
		$this->theme->set_layout("member");
	}

	public function get_index(){
		$user = Auth::user();

		$data['title'] = 'Profile';
		$data['user'] = $user;

		/*-- META DATA */
		$data['title'] = "Member Dashboard";
		$this->theme->title($data['title'].' - '.Settings::get('en','site_title'));
		/*-- BREADCRUMB */
		 
		Breadcrumb::addbreadcrumb('Home', URL::base());
		Breadcrumb::addbreadcrumb($data['title'], URL::base());
		Breadcrumb::setSeparator('&raquo;');
		$data['breadcrumb'] = Breadcrumb::generate();
		return $this->theme->render('member::profile', $data);
	}

	public function post_index(){
		
			$rules = array(
					'name' => 'required',
					'user_name' => 'required|between:4,50',
					'password'         => 'required',
					'password_confirm' => 'required|same:password',
			);

			
			if(Input::get('password') == TRUE){
			
			$v = Validator::make(Input::all(), $rules);
			 
			$thisOrderid = Input::get('memID');
			 
			if( $v->fails() )
			{
				//code for validation failure :(
				return Redirect::back()
				->with_errors($v)
				->with_input();
			}
			else
			{

				DB::table('users')->where('id','=',$thisOrderid)->update(array(
							
						'name' => Input::get('name'),
						'username' => Input::get('user_name'),
						'password' => Hash::make(Input::get('password')),
				));
			}
		}else{
			 
			$thisOrderid = Input::get('memID');
			
			DB::table('users')->where('id','=',$thisOrderid)->update(array(

					'name' => Input::get('name'),
					'username' => Input::get('user_name'),
					//'password' => Hash::make(Input::get('password')),
			));

		}
		 
		$msg = '<div class="alert alert-info">Successfully Updated....</div>';
		return Redirect::back()->with('message',$msg);
		 
		 
	}
}